/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.math.BigInteger;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author WinKiQue58
 */
@Entity
@Table(name = "ITEM_CAMPAIGN")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ItemCampaign.findAll", query = "SELECT i FROM ItemCampaign i"),
    @NamedQuery(name = "ItemCampaign.findByIdItemCampaign", query = "SELECT i FROM ItemCampaign i WHERE i.itemCampaignPK.idItemCampaign = :idItemCampaign"),
    @NamedQuery(name = "ItemCampaign.findByIdCampaign", query = "SELECT i FROM ItemCampaign i WHERE i.itemCampaignPK.idCampaign = :idCampaign")})
public class ItemCampaign implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ItemCampaignPK itemCampaignPK;
    @JoinColumns({
        @JoinColumn(name = "ID_PRODUCT", referencedColumnName = "ID_PRODUCT"),
        @JoinColumn(name = "ID_BRANCHENTERPRISE1", referencedColumnName = "ID_BRANCHENTERPRISE"),
        @JoinColumn(name = "ID_ENTERPRISE1", referencedColumnName = "ID_ENTERPRISE"),
        @JoinColumn(name = "ID_ITEM", referencedColumnName = "ID_ITEM")})
    @OneToOne(optional = false, fetch = FetchType.LAZY)
    private Item item;
    @JoinColumn(name = "ID_CAMPAIGN", referencedColumnName = "ID_CAMPAIGN", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Campaign campaign;

    public ItemCampaign() {
    }

    public ItemCampaign(ItemCampaignPK itemCampaignPK) {
        this.itemCampaignPK = itemCampaignPK;
    }

    public ItemCampaign(BigInteger idItemCampaign, BigInteger idCampaign) {
        this.itemCampaignPK = new ItemCampaignPK(idItemCampaign, idCampaign);
    }

    public ItemCampaignPK getItemCampaignPK() {
        return itemCampaignPK;
    }

    public void setItemCampaignPK(ItemCampaignPK itemCampaignPK) {
        this.itemCampaignPK = itemCampaignPK;
    }

    public Item getItem() {
        return item;
    }

    public void setItem(Item item) {
        this.item = item;
    }

    public Campaign getCampaign() {
        return campaign;
    }

    public void setCampaign(Campaign campaign) {
        this.campaign = campaign;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (itemCampaignPK != null ? itemCampaignPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ItemCampaign)) {
            return false;
        }
        ItemCampaign other = (ItemCampaign) object;
        if ((this.itemCampaignPK == null && other.itemCampaignPK != null) || (this.itemCampaignPK != null && !this.itemCampaignPK.equals(other.itemCampaignPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.ItemCampaign[ itemCampaignPK=" + itemCampaignPK + " ]";
    }
    
}
